package com.yuexin.project.abutment.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yuexin.framework.web.controller.BaseController;
import com.yuexin.framework.web.domain.AjaxResult;
import com.yuexin.project.abutment.domain.Company;
import com.yuexin.project.abutment.mapper.AbutmentMapper;

/**
 * 首页 业务处理
 * 
 * @author yuexin
 */
@Controller
@RequestMapping("/abutment")
public class AbutmentController extends BaseController
{
	@Autowired
	private AbutmentMapper abutmentMapper;
	
    // 系统首页
    @GetMapping("/notopen")
    public String index(ModelMap mmap)
    {
        return "/abutment/notopen";
    }
    
    @GetMapping("/setaccount")
    public String setaccount(ModelMap mmap)
    {
        return "/abutment/setaccount";
    }
    
    @GetMapping("/firstLogin")
    public String firstLogin(ModelMap mmap)
    {
        return "/abutment/firstLogin";
    }
    
    @GetMapping("/errorpage")
    public String errorpage(ModelMap mmap)
    {
        return "/abutment/errorpage";
    }
    
    @GetMapping("/loading")
    public String loading(ModelMap mmap)
    {
        return "/abutment/loading";
    }
    
    @GetMapping("/probation")
    public String probation(ModelMap mmap)
    {
        return "/abutment/probation";
    }
    
    @GetMapping("/application")
    public String application(ModelMap mmap)
    {
        return "/abutment/application";
    }
    
    @GetMapping("/getProbationDate")
    @ResponseBody
    public AjaxResult getProbationDate(String orgId)
    {
    	Map<String,Integer> map = new HashMap<String,Integer>();
    	
    	Company comp = abutmentMapper.selectCompany(orgId);
    	Date expiredDate = comp.getExpiredDate();
    	int days = (int) ((expiredDate.getTime() - new Date().getTime()) / (1000*3600*24));
    	map.put("days", days);
        return success(map);
    }
    
    @PostMapping("/application")
	@ResponseBody
    public AjaxResult application(String applyArea,String orgName,String applyName,String applyPhone)
    {
    	Company comp = new Company();
    	comp.setApplyArea(applyArea);
    	comp.setOrgName(orgName);
    	comp.setApplyName(applyName);
    	comp.setApplyPhone(applyPhone);
    	comp.setStatus("2");
    	abutmentMapper.insertCompany(comp);
    	return success();
    }
    

    @GetMapping("/firstMobile")
    public String firstMobile(ModelMap mmap)
    {
        return "/abutment/firstMobile";
    }
}
